package week01

// 142. 环形链表 II
// https://leetcode-cn.com/problems/linked-list-cycle-ii/

// 快慢指针

func detectCycle(head *ListNode) *ListNode {
	var start *ListNode
	var quick, slow = head, head
	for quick != nil && quick.Next != nil {
		quick = quick.Next.Next
		slow = slow.Next
		if slow == quick {
			start = head
			for slow != start {
				slow = slow.Next
				start = start.Next
			}
			break
		}
	}
	return start
}

type ListNode struct {
	Val int
	Next *ListNode
}